import { ColumnProps } from "@/components/ProTable/interface";
import { authTypeEnum, booleanEnum, statusEnum } from "@/config/enums/serviceDict.ts";

export function auth(authTree: any[]) {
  const columns: ColumnProps[] = [
    { type: "selection", fixed: "left", width: 80 },
    { type: "index", label: "#", width: 80 },
    {
      prop: "pid",
      label: "上级菜单",
      width: 150,
      isShow: false,
      fieldNames: {
        label: "title",
        value: "id"
      },
      enum: authTree,
      search: {
        el: "tree-select",
        props: { filterable: true, label: "title", value: "id", checkStrictly: true, placeholder: "上级菜单", style: "width:180px;" }
      }
    },
    {
      prop: "title",
      label: "标题",
      width: 150,
      align: "left",
      search: { el: "input", props: { placeholder: "请输入标题", style: "width: 180px" } }
    },
    {
      prop: "icon",
      label: "ICON",
      width: 120
    },
    {
      prop: "name",
      label: "名称",
      width: 150,
      search: { el: "input", props: { placeholder: "请输入名称", style: "width: 180px" } }
    },
    {
      prop: "type",
      label: "类型",
      width: 120,
      enum: authTypeEnum,
      search: { el: "select", props: { filterable: true, placeholder: "权限类型", style: "width: 120px;" } }
    },
    {
      prop: "router",
      label: "路由地址",
      width: 150,
      search: { el: "input", props: { placeholder: "路由地址", style: "width: 180px;" } }
    },
    {
      prop: "component",
      label: "组件地址",
      width: 200,
      search: { el: "input", props: { placeholder: "组件地址", style: "width: 180px;" } }
    },
    {
      prop: "iframe",
      label: "是否外链",
      width: 100,
      enum: booleanEnum,
      search: { el: "select", props: { placeholder: "是否外链", style: "width: 100px;" } }
    },
    {
      prop: "link",
      label: "链接",
      width: 200
    },
    {
      prop: "auth_key",
      label: "权限标识",
      width: 150
    },
    {
      prop: "sort",
      label: "排序",
      width: 150
    },
    {
      prop: "hidden",
      label: "是否隐藏",
      width: 100,
      enum: booleanEnum,
      search: { el: "select", props: { placeholder: "是否隐藏", style: "width: 100px;" } }
    },
    {
      prop: "status",
      label: "状态",
      width: 100,
      enum: statusEnum,
      search: { el: "select", props: { placeholder: "状态", style: "width: 100px;" } }
    },
    {
      prop: "create_time",
      label: "创建时间",
      width: 180,
      search: {
        el: "date-picker",
        key: "dateTimeRange",
        props: { type: "datetimerange", valueFormat: "YYYY-MM-DD HH:mm:ss", clearable: true, style: "width: 240px;" }
      }
    },
    { prop: "operation", label: "操作", fixed: "right", width: 320 }
  ];
  return { columns };
}
